package com.yuexunit.mobilenurse.module.SkinTest.ui;

import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.yuexunit.mobilenurse.R;
import com.yuexunit.mobilenurse.base.titlebar.TitleBar_DocAdvice;
import com.yuexunit.mobilenurse.config.AppConfig;
import com.yuexunit.mobilenurse.module.Inspect.adapter.InspectAdapter;
import com.yuexunit.mobilenurse.module.Inspect.presenter.IInspectPresenter;
import com.yuexunit.mobilenurse.module.SkinTest.adapter.SkinTestAdapter;
import com.yuexunit.mobilenurse.module.SkinTest.bean.SkinTestListBean;
import com.yuexunit.mobilenurse.module.SkinTest.model.impl.SkinTestListModel;
import com.yuexunit.mobilenurse.module.SkinTest.presenter.ISkinTestListPresenter;
import com.yuexunit.mobilenurse.module.SkinTest.presenter.impl.SkinTestListPresenter;
import com.yuexunit.mobilenurse.module.SkinTest.ui.view.ISkinTestListView;
import com.yuexunit.mobilenurse.widget.EmptyLayout;

import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.KJLoger;
import org.kymjs.kjframe.utils.PreferenceHelper;
import org.kymjs.kjframe.utils.SystemTool;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/3/13 0013.
 */

public class Act_SkinTestList extends TitleBar_DocAdvice implements ISkinTestListView{
    @Bind(R.id.act_skintest_list)
    public ListView act_skintest_list;
    @Bind(R.id.empty_layout)
    public EmptyLayout mEmptyLayout;
    @Bind(R.id.titlebar_docadvice_tv_title)
    public TextView titlebar_docadvice_tv_title;
    @Bind(R.id.docactvice_name)
    public TextView docactvice_name;
    @Bind(R.id.docactvice_bedno)
    public TextView docactvice_bedno;
    @Bind(R.id.docactvice_visitno)
    public TextView docactvice_visitno;

    private BaseAdapter adapter;
    //病人住院号
    private  String Visitno;
    ISkinTestListPresenter presenter;


    @Override
    public void setRootView() {
        setContentView(R.layout.act_skintestlist);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        presenter = new SkinTestListPresenter(this,new SkinTestListModel());
        Visitno = PreferenceHelper.readString(aty, AppConfig.CURRENT_PATIENT_INFO, AppConfig.CURRENT_PATIENT_VISITNO);
        mEmptyLayout.setOnLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEmptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
            }
        });
    }

    protected void onResume() {
        super.onResume();
        if(SystemTool.checkNet(aty)) {
            presenter.showSkinTestList(Visitno);
        }
        else
        {
            ViewInject.toast("网络异常，请检查网络是否连接!");
        }
    }


    @Override
    public void setTitle()
    {
        titlebar_docadvice_tv_title.setText("皮试列表");
        docactvice_name.setText(PreferenceHelper.readString(aty, AppConfig.CURRENT_PATIENT_INFO, AppConfig.CURRENT_PATIENT_NAME));
        docactvice_bedno.setText(PreferenceHelper.readString(aty, AppConfig.CURRENT_PATIENT_INFO, AppConfig.CURRENT_PATIENT_BEDCODE));
        docactvice_visitno.setText(PreferenceHelper.readString(aty, AppConfig.CURRENT_PATIENT_INFO, AppConfig.CURRENT_PATIENT_VISITNO));
    }

    @Override
    public  void onBackClick()
    {
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void showSkinTestList(ArrayList<SkinTestListBean> list) {
        adapter = new SkinTestAdapter(act_skintest_list, list, R.layout.item_skintest_list);
        act_skintest_list.setAdapter(adapter);
        mEmptyLayout.dismiss();
    }
}
